<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" size="mini">
      <el-form-item label="任务名称">
        <el-input v-model="form.name" ></el-input>
      </el-form-item>
	  <el-form-item label="任务描述">
	    <el-input v-model="form.details" ></el-input>
	  </el-form-item>
      <el-form-item label="所属项目">
		  <el-select v-model="form.project" filterable >
		    <el-option
		      v-for="item in projectNames"
		      :key="item"
		      :label="item"
		      :value="item">
		    </el-option>
		  </el-select>
      </el-form-item>

      <el-form-item label="指派给">
        <el-input v-model="form.assign"  ></el-input>
      </el-form-item>
	  <el-form-item label="课时">
	    <el-input v-model="form.classHours" ></el-input>
	  </el-form-item>
	  

      <el-form-item>
        <el-button type="primary" plain @click="save">保存数据</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from '../../utils/axiosutils.js'
  export default {
    name: 'RoleEdit',
    props: ['editname','status'],
    data() {
      return {
		  time:[],
        form: {
			id:'',
			name:'',
			details:'',
			project:'',
			assign:'',
			stime:'',
			etime:'',
			classHours:'',
			status:''
        },
		projectNames:[]
      }
    },
	created() {
		if (this.editname) {
			axios.get(
				'/task/getByName',
				response => {
					this.form.id=response.obj.id;
					this.form.name = response.obj.name;
					this.form.details = response.obj.details;
					this.form.project = response.obj.project;
					this.form.assign = response.obj.assign;
					this.form.stime = response.obj.stime;
					this.form.etime = response.obj.etime;
					this.form.classHours = response.obj.classHours;
					this.form.status = this.status;
				}, {
					name: this.editname
				}
			);
		}
		axios.get(
			"/project/myProjects",
			resp=>{
				this.projectNames=resp.obj.names;
			}
		);
	},
	methods: {
		save: function() {
			console.log(this.status);
			if(this.status==1){
				axios.post('task/stastart',resp=>{
					console.log(resp)
					axios.post(
						'/task/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				},{id:this.form.id})
			}else if(this.status==2){
				axios.post('task/stapuase',resp=>{
					axios.post(
						'/task/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				},{id:this.form.id})
			}else if(this.status==3){
				axios.post('task/stacomplete',resp=>{
					
					axios.post(
						'/task/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				},{id:this.form.id})
			}
			
		}
	}
  }
</script>

<style>
</style>
